package com.gitee.bluebird;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

/**
 ** @createtime : 2018/11/26 8:07 PM
 **/
public class NettyDecoder extends LengthFieldBasedFrameDecoder {

    public NettyDecoder(BootstrapConf bootstrapConf) {
        super(bootstrapConf.getMaxFrameLen(), 0, 4, 0, 4);
    }

    @Override
    protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
        ByteBuf byteBuf = (ByteBuf) super.decode(ctx, in);
        if(byteBuf == null){
            return null;
        }

        return new Packet(byteBuf);
    }
}
